package ch.cern



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(PointService)
@Mock([Tag, Point, Map])
class PointServiceTests
{
  PointService pointService = new PointService()

  void setUp() {
    BootStrapUnit.bootStrap()
  }

  void testMocking() {
    def map = Map.findByName("Dubna")
    def points = Point.list()
    assert map != null
    assert points.size() == 4
    //assert map.points == 4 bug in 2.0.3, cannot do this
    points.each{assert it.map == map; assert it.tags.size() > 0}
  }

  void testGetStats() {
    def points = Point.list()
    def stats = pointService.getStats(points)
    assert stats.count == 4
    assert stats.fromDate == points.find {it.title == "University"}.createdOn
    assert stats.toDate == points.find {it.title == "Dubna Pizza"}.createdOn
    assert stats.tags.size() == 4
    assert stats.tags.work.size() == 2
    assert stats.tags.drink.size() == 2
    assert stats.tags.restaurant.size() == 2
    assert stats.tags.holiday.size() == 1
  }

}
